osdep/unix/getroot: Fix potential underflow
authorLidong Chen <lidong.chen@oracle.com>
Wed, 29 Jan 2025 06:48:38 +0000 (06:48 +0000)
committerMiao Wang <shankerwangmiao@gmail.com>
Sun, 15 Feb 2026 13:50:20 +0000 (13:50 +0000)
commit263e70a22134c41b51e7c9f636d45514a932469a
tree93f44166969633c9531d591d932c2fae4e91e674
parentc38e98f7a86a90cc1983cd93f18f461a80bab515
osdep/unix/getroot: Fix potential underflow

The entry_len is initialized in grub_find_root_devices_from_mountinfo()
to 0 before the while loop iterates through /proc/self/mountinfo. If the
file is empty or contains only invalid entries entry_len remains
0 causing entry_len - 1 in the subsequent for loop initialization
to underflow. To prevent this add a check to ensure entry_len > 0 before
entering the for loop.

Fixes: CID 473877
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name osdep-unix-getroot-Fix-potential-underflow.patch
grub-core/osdep/linux/getroot.c